package cc.rboot.inject.template;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cc.rboot.inject.core.AbstractMapperInjector;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/_inject")
public class InjectQuery<T> extends AbstractMapperInjector<T> {

    /**
     * 默认的按条件查询接口：带分页
     *
     * @param entity
     * @param page
     * @return
     * @throws Exception
     */
    @GetMapping(path = "/collect/query")
    public IPage<T> _execute(Page<T> page, T entity) throws Exception {
        Wrapper<T> wrapper = new QueryWrapper<>(entity);
        return super.getService().page(page, wrapper);
    }
}
